<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>vue2 sync</title>
    <script src="./vue.js"></script>
</head>
<body>
    <div id="app">
        <sun-comp01 :obj.sync="obj"></sun-comp01>
        <!-- <sun-comp01 :obj="obj" @update:obj="obj = $event"></sun-comp01> -->
    </div>
    <script>
        Vue.component('SunComp01', {
            props: ['obj'],
            template: `
                <div>
                    <p>{{obj.name}}</p>
                    <p>{{obj.age}}</p>
                    <button @click='change'>改变</button>
                </div>
            `,
            methods: {
                change() {
                    this.$emit("update:obj", {
                        name: this.obj.name + 1,
                        age: this.obj.age + 1
                    })
                }
            }
        })
        new Vue({
            data() {
                return {
                    obj: {
                        name: '孙小双', age: 33
                    }
                }
            }
        }).$mount("#app")
    </script>
</body>
</html>